<?php
namespace app\api\controller;

use app\common\model\AddressModel;
use think\Db;

class Recycling extends Common
{
    public function getList()
    {
        $this->checkSign(false);
        $list = Db::name('recycling_type')->cache(true)->field('id,title,describe,icon,is_open,left_color,in_icon,right_color')->select();
        return package(0,'success',$list);
    }
    public function getTypePrice(){
        $data = $this->checkSign();

        $addModel = new AddressModel();
        $regId = $addModel->findRegion($data['latitude']??'',$data['longitude']??'');
        if(!$regId){
            return  clientReturnJson('10005','当前区域未开通!');
        }
        $list =Db::name('recycling_list')
            ->field('id,type_id,name,describe,unit,reference_price')
            ->select();
        $in = '';
        foreach ($list as $v){
            $in.=$v['id'].',';
        }
        $prices = Db::name('recycling_reg_price')
            ->where('region_id',$regId['region_id'])
            ->whereIn('list_id',$in)
            ->field('price,list_id')
            ->select();
        foreach ($prices as $v){
            foreach ($list as $key =>$val){
                if($val['id'] ==$v['list_id']){
                    $list[$key]['price'] = $v['price'];
                }
            }
        }
        return package(0,'success',$list);
    }
}